﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.Xpo.DB;
using DevExpress.Xpo;
using DevExpress.Data.Filtering;
using System.IO;
using DevExpress.Utils.Drawing;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using Ebada.Client.Platform;

namespace sample1.MillionsDataDemo {

    public partial class UserControl2 : UserControl {
        public UserControl2() {
            string conn = "";
            conn = MainHelper.GetSqlMap<Ebada.PlatformLog.Model.mLog_Operate>().GetConnectionString();
            IDataStore store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.DatabaseAndSchema);
            store = new WaitCursorWrapper(store);
            XpoDefault.DataLayer = new SimpleDataLayer(store);
            InitializeComponent();
            gridView1.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gridView1_FocusedRowChanged);
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) {
            object obj = gridView1.GetFocusedRow();
        }
        private void gridControl1_Click(object sender, EventArgs e) {

        }

        private void simpleButton1_Click(object sender, EventArgs e) {
            xpServerCollectionSource1.FixedFilterString = "LoginName like '123%'";
        }
    }
    public class WaitCursorWrapper : IDataStore {
        public readonly IDataStore Nested;
        public WaitCursorWrapper(IDataStore nested) {
            this.Nested = nested;
        }
        public AutoCreateOption AutoCreateOption {
            get { return Nested.AutoCreateOption; }
        }
        public ModificationResult ModifyData(params ModificationStatement[] dmlStatements) {
            try {
                Cursor.Current = Cursors.WaitCursor;
                return Nested.ModifyData(dmlStatements);
            } finally {
                Cursor.Current = Cursors.Default;
            }
        }
        public SelectedData SelectData(params SelectStatement[] selects) {
            try {
                Cursor.Current = Cursors.WaitCursor;
                return Nested.SelectData(selects);
            } finally {
                Cursor.Current = Cursors.Default;
            }
        }
        public UpdateSchemaResult UpdateSchema(bool dontCreateIfFirstTableNotExist, params DBTable[] tables) {
            try {
                Cursor.Current = Cursors.WaitCursor;
                return Nested.UpdateSchema(dontCreateIfFirstTableNotExist, tables);
            } finally {
                Cursor.Current = Cursors.Default;
            }
        }

    }
       
}
